/********************************************************************
* Name: X86AsmOptimizer.h: 
*
* Description:
*   Interface & management class of post-pass optimization
*   
*
* History:
*   Create: gxf. 2009-03-28
*
********************************************************************/
#ifndef X86_ASM_OPTIMIZER_H
#define X86_ASM_OPTIMIZER_H

#include <iostream>
#include <vector>
#include <algorithm>

namespace crossbit{

class X86AsmOptimizer{
    public:
        X86AsmOptimizer(){}
        virtual ~X86AsmOptimizer(){}

    public:
        virtual Apply(AsmBlock* asmBlock){};

        INLINE static bool ApplyOpt(AsmBlock* asmBlock){
            std::vector<X86AsmOptimizer*>::iterator itr = optmizs.begin();
            while(itr != optmizs.end()){ 
                (*itr) -> Apply(asmBlock);
                ++itr;
            }
        }

        // Register & UnRegister optimizers
        INLINE static bool RegOptmiz(X86AsmOptimizer* optmiz){
            if (optmiz != NULL){
                optmizs.push_bash(optmiz);
                return true;
            }
            return false;
        }

        INLINE static void UnRegOptmiz(X86AsmOptimizer* optmiz){
            std::vector<X86AsmOptimizer*>::iterator begin = optmizs.begin();
            std::vector<X86AsmOptimizer*>::iterator end = optmizs.end();

            optimizs.erase(std::remove(begin, end, optimiz), end);
        }

    protected:
        static std::vector<X86AsmOptimizer* > optmizs;

}; // X86AsmOptimizer

} // crossbit

#endif

